#pragma once

#include "log/logger.h"
#include "log/log_registry.h"

namespace xlog {

void set_level(const log_level level)
{
    log_registry::instance().set_global_level(level);
}

template<typename FormatString, typename... Args>
inline void debug(const FormatString &fmt, Args&& ...args)
{
    log_registry::instance().get_default_logger()->debug(fmt, std::forward<Args>(args)...);
}

template<typename FormatString, typename... Args>
inline void info(const FormatString &fmt, Args&& ...args)
{
    log_registry::instance().get_default_logger()->info(fmt, std::forward<Args>(args)...);
}

template<typename FormatString, typename... Args>
inline void warn(const FormatString &fmt, Args&& ...args)
{
    log_registry::instance().get_default_logger()->warn(fmt, std::forward<Args>(args)...);
}

template<typename FormatString, typename... Args>
inline void error(const FormatString &fmt, Args&& ...args)
{
    log_registry::instance().get_default_logger()->error(fmt, std::forward<Args>(args)...);
}

// 日志静态级别开关，默认为开
#ifndef XLOG_ACTIVE_LEVEL 
#define XLOG_ACTIVE_LEVEL XLOG_LOG_LEVEL_ON
#endif

#define XLOG_LOG_LEVEL(level, logger, ...) logger->log(level, __VA_ARGS__);

#if XLOG_ACTIVE_LEVEL <= XLOG_LOG_LEVEL_TRACE
#define XLOG_TRACE(...) XLOG_LOG_LEVEL(xlog::log_level::trace, xlog::log_registry::instance().get_default_logger(), __VA_ARGS__)
#else
#define XLOG_TRACE(...) (void)0
#endif

#if XLOG_ACTIVE_LEVEL <= XLOG_LOG_LEVEL_DEBUG
#define XLOG_DEBUG(...) XLOG_LOG_LEVEL(xlog::log_level::debug, xlog::log_registry::instance().get_default_logger(), __VA_ARGS__)
#else
#define XLOG_DEBUG(...) (void)0
#endif

#if XLOG_ACTIVE_LEVEL <= XLOG_LOG_LEVEL_INFO
#define XLOG_INFO(...) XLOG_LOG_LEVEL(xlog::log_level::info, xlog::log_registry::instance().get_default_logger(), __VA_ARGS__)
#else
#define XLOG_INFO(...) (void)0
#endif

#if XLOG_ACTIVE_LEVEL <= XLOG_LOG_LEVEL_WARN
#define XLOG_WARN(...) XLOG_LOG_LEVEL(xlog::log_level::warn, xlog::log_registry::instance().get_default_logger(), __VA_ARGS__)
#else
#define XLOG_WARN(...) (void)0
#endif

#if XLOG_ACTIVE_LEVEL <= XLOG_LOG_LEVEL_ERROR
#define XLOG_ERROR(...) XLOG_LOG_LEVEL(xlog::log_level::error, xlog::log_registry::instance().get_default_logger(), __VA_ARGS__)
#else
#define XLOG_ERROR(...) (void)0
#endif

}